def flashBinIntoModule(command_dict, conn):
    if 'modid' not in command_dict:
        return {"cmdAck": "flash", "reqId": command_dict.get("reqId"), "code": "910", "msg": "Invalid parameters: modid is required"}

    if 'hubId' not in command_dict:
        return {"cmdAck": "flash", "reqId": command_dict.get("reqId"), "code": "910", "msg": "Invalid parameters: hubId is required"}

    if DEBUG_MODE:
        return {"cmdAck": "flash", "reqId": command_dict.get("reqId"), "code": "200", "msg": "success"}

    #getHubInfo
    headers = {'token': TOKEN}
    data = {'module_id': command_dict['modid'], 'user_name': AGENT_NAME, 'prod_code': command_dict['prodCode']}
    url = SERVER_HOST+"getHubInfoByModuleId"

    api_res = requests.post(url, headers=headers, json=data)    
    if api_res.status_code == 200:
        api_res_json = api_res.json()
        print(api_res_json)
        #checkModuleStatus and hubData
        if (api_res_json['code'] == '200'):
            if (api_res_json['module']['status']=='F'):
                #downloadBin
                fw_bin_file = getFwBinFileName(api_res_json['module']['prod_code'],'')
                if(fw_bin_file is None):
                    return {"cmdAck": "flash", "reqId": command_dict.get("reqId"), "code": "951", "msg": "Failed to get fw bin file name"}

                print(fw_bin_file)
                
                input("Press Enter to continue...")
                #check if BIN folder exist                
                if not os.path.exists(FIRMWARE_PATH+fw_bin_file['combined_file']):
                    #download bin file
                    print("downloading bin file...")
                    download(FILESERVER_HOST, fw_bin_file['combined_file'], FIRMWARE_PATH)
                    #download bin file
                    print("downloaded bin file!")
                
                input("Press Enter to continue...")
                CFG_FILE_DIR = HUB_CFG_PATH + api_res_json['module']['hub_id']
                if not os.path.exists(CFG_FILE_DIR):                    
                    config_bin_file_name = api_res_json['module']['hub_id'] + ".zip"
                    #download cfg bin file
                    download_and_unzip(FILESERVER_HOST, config_bin_file_name, TMP_PATH, HUB_CFG_PATH)
                    print("downloading cfg bin file...")
                    #download(FILESERVER_HOST, config_bin_file_name, TMP_PATH, HUB_CFG_PATH)                    
                    
                input("Press Enter to continue...")
                status, step = get_hub_status(api_res_json['module']['module_id'], api_res_json['module']['prod_code'])
                
                print("status:", status, "step:", step)
                input("Press Enter to continue...")
                if(status == 'F'):
                    current_step = 0
                    if(step is None or step == ''):
                        current_step = 2
                    else:
                        current_step = int(step) + 1
                    
                    while(current_step <= 6):
                        result = flashProc(command_dict, current_step, FIRMWARE_PATH, fw_bin_file['combined_file'], HUB_CFG_PATH, api_res_json['module']['hub_id'])
                        if(result['code'] == '200'):
                            #conn.sendall(json.dumps(result).encode())
                            update_hub_burn_status(api_res_json['module']['module_id'], api_res_json['module']['prod_code'], 'F', current_step)
                            current_step = current_step + 1
                            print("current_step:", current_step)
                            input("Press Enter to continue...")
                        else:
                            return result                                                                    
                else:
                    return {"cmdAck": "flash", "reqId": command_dict.get("reqId"), "code": "952", "msg": f"Wrong module status {status}, can not flash bin file"}
                #check if bin file flashed
                print("flash bin file completed!")
                url = SERVER_HOST+"completeFlash"
                api_res = requests.post(url, headers=headers, json=data)
                return {"cmdAck": "flash", "reqId": command_dict.get("reqId"), "code": "200", "msg": "Success"}
            else:
                return {"cmdAck": "flash", "reqId": command_dict.get("reqId"), "code": "952", "msg": f"Wrong module status {api_res_json['module']['status']}, can not flash bin file"}
        else:
            return {"cmdAck": "flash", "reqId": command_dict.get("reqId"), "code": api_res_json['code'], "msg": api_res_json['message']}
    else:
        return {"cmdAck": "format", "reqId": command_dict.get("reqId"), "code": "909", "msg": "Failed to connect dcms server"}        